package lowijs.XfireClient.packet;

public class LoginReplyPacket extends Packet {
	private byte[] userid = new byte[4];
	private byte[] sid = new byte[16];
	private byte[] status = new byte[4];
	private String nickname;
	
	public LoginReplyPacket(byte[] data) {
		System.arraycopy(data, 11, userid, 0, 4);
		System.arraycopy(data, 20, sid, 0, 16);
		
		int namelengthLen = data[41] & 0xFF;
		int nameLen = 0, startbyte = 0;
		if (namelengthLen == 1) {
			nameLen = data[42] & 0xFF;
			startbyte = 44;
		} else {
			nameLen = fromLowHigh(data[42], data[43]);
			startbyte = 45;
		}
		
		if (data[startbyte] != 0) {
			byte[] nameBytes = new byte[nameLen];
			System.arraycopy(data, startbyte, nameBytes, 0, nameLen);
			nickname = new String(nameBytes);
		} else
			nickname = "";
		
		startbyte += nameLen + 8;
		System.arraycopy(data, startbyte, status, 0, 4);
	}
	
	public byte[] getUserId() {
		return userid;
	}
	
	public byte[] getSid() {
		return sid;
	}
	
	public String getNickname() {
		return nickname;
	}
	
	public byte[] getStatus() {
		return status;
	}
}
